package easy;

import java.util.HashMap;
import java.util.Map;

public class Solution_2062 {

    public int countVowelSubstrings(String word) {
        int count = 0;
        word += ' ';
        char[] chars = word.toCharArray();
        for (int i = 0, num = 0; i < chars.length; i++) {
            char c = chars[i];
            if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
                num++;
            } else {
                if (num > 0) {
                    count += count(chars, i - num, i - 1);
                }
                num = 0;
            }
        }
        return count;
    }

    private int count(char[] chars, int begin, int end) {
        int count = 0;
        if (begin + 4 <= end) {

        }
        for (int j = 5; j <= end - begin + 1; j++) {
            Map<Character, Integer> map = new HashMap<>();
            for (int i = begin; i < begin + j - 1; i++) {
                map.put(chars[i], map.getOrDefault(chars[i], 0) + 1);
            }
            for (int i = begin + j - 1; i <= end; i++) {
                map.put(chars[i], map.getOrDefault(chars[i], 0) + 1);
                if (check(map)) {
                    count++;
                }
                map.put(chars[i - j + 1], map.get(chars[i - j + 1]) - 1);
            }
        }
        return count;
    }

    private boolean check(Map<Character, Integer> map) {
        return map.getOrDefault('a', 0) > 0
            && map.getOrDefault('e', 0) > 0
            && map.getOrDefault('i', 0) > 0
            && map.getOrDefault('o', 0) > 0
            && map.getOrDefault('u', 0) > 0;
    }

    public static void main(String[] args) {
        Solution_2062 model = new Solution_2062();
        System.out.println(model.countVowelSubstrings("aeiouu"));
        System.out.println(model.countVowelSubstrings("unicornarihan"));
        System.out.println(model.countVowelSubstrings("cuaieuouac"));
    }
}
